import React, { Component } from 'react'
import { Row, Col } from 'antd'
import Utils from '../../utils/Utils'
import Axios from '../../axios'
import './index.less'
 
class Header extends Component{
    state = {}
    componentDidMount(){
        this.setState({
            userName: '稻城'
        })
        setInterval(()=>{
            let sysTime = Utils.formateDate(new Date().getTime())
            this.setState({
                sysTime
            })
        },1000)
        // this.getWeaterApiDate()
    }

    //获取百度天气API数据
    getWeaterApiDate(){
        let city = '杭州';
        Axios.jsonp({
            url: 'http://api.map.baidu.com/telematics/v3/weather?location='+encodeURIComponent(city)+'&output=json&ak=3p49MVra6urFRGOT9s8UBWr2'
        }).then((res)=>{
            if(res.status == 'success'){
                let data = res.results[0].weather_data[0]
                this.setState({
                    dayPictureUrl: data.dayPictureUrl,
                    weather: data.weather
                })
            }
        })
    }
    render(){
        return (
            <div className="header">
                <Row className="header-top">
                    <Col>
                        <span>欢迎，{this.state.userName}</span>
                        <a href="##">退出</a>
                    </Col>
                </Row>
                <Row className="breadcrumb">
                    <Col span="4" className="breadcrumb_title">
                        首页
                    </Col>
                    <Col span="20" className="weather">
                        <span className="date">{this.state.sysTime}</span>
                        <img src={this.state.dayPictureUrl} alt="" className="weather_img"/>
                        <span className="weather_detail">{this.state.weather}</span>
                    </Col>
                </Row>
            </div>
        )
    }
}
export default Header